package subumbo.micro.view
{
	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.geom.Point;
	
	public class Shape extends Sprite
	{
		static public const RECTANGLE:String = "rect";
		static public const CIRCLE:String = "circ";
		static public const ROUND_RECT:String = "round_rect";
		static public const TRIANGLE:String = "triangle";
		static public const ELIPSIS:String = "elipsis";
		
		public function Shape(fillColor:uint=0, type:String="Rectabgle", width:Number=600, height:Number=400, offSet:Point=null, fillAlpha:Number=1, corner:Number=15)
		{
			draw(fillColor, type, width, height, offSet, fillAlpha, corner);
		}
		
		public function draw(fillColor:uint=0, type:String="Rectabgle", width:Number=600, height:Number=400, offSet:Point=null, fillAlpha:Number=1, corner:Number=15):void
		{
			var g:Graphics = this.graphics;
			g.clear();
			g.beginFill(fillColor, fillAlpha);
			if(!offSet) offSet = new Point();
			switch(type)
			{
				case RECTANGLE :
					g.drawRect(offSet.x, offSet.y, width, height);
					break;
				
				case CIRCLE :
					g.drawCircle(offSet.x, offSet.y, width);
					break;
				
				case ROUND_RECT :
					g.drawRoundRect(offSet.x, offSet.y, width, height, corner);
					break;
				
				case TRIANGLE :
					var b:Number = width*.5;
					var h:Number = Math.sqrt(width*width - b*b);
					g.moveTo(b+offSet.x,0+offSet.y);
					g.lineTo(width+offSet.x, h+offSet.y);
					g.lineTo(0+offSet.x, h+offSet.y );
					g.lineTo(b+offSet.x,0+offSet.y);
					break;
				
				case ELIPSIS :
					g.drawEllipse(offSet.x, offSet.y, width, height);
					break;
			}
			g.endFill();
		}
	}
}